From 9f2329da170eede6256a7b0d390b9534f3c14746 Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 10 Feb 2003 19:47:29 +0000 Subject: [PATCH] Hash and compare are now case insenstitive - this is to compensate for mapsource which will not let you have both ThisName and Thisname. --- gpsbabel/mkshort.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gpsbabel/mkshort.c b/gpsbabel/mkshort.c index 64d17d91f..9ceaef953 100644 --- a/gpsbabel/mkshort.c +++ b/gpsbabel/mkshort.c @@ -33,11 +33,14 @@ typedef struct { int conflictctr; } uniq_shortname; +/* + * We hash all strings as upper case. + */ unsigned int hash_string(const char *key) { unsigned int hash = 0; while (*key) { - hash = ((hash<<5) ^ (hash>>27)) ^ *key++; + hash = ((hash<<5) ^ (hash>>27)) ^ toupper(*key++); } hash = hash % PRIME; return hash; @@ -72,14 +75,21 @@ mkshort_add_to_list(mkshort_handle *h, char *name) QUEUE_FOR_EACH(&h->namelist[hash], e, t) { uniq_shortname *z = (uniq_shortname *) e; - if (0 == strcmp(z->orig_shortname, name)) { + if (0 == case_ignore_strcmp(z->orig_shortname, name)) { int l = strlen(name); int dl; char tbuf[10]; z->conflictctr++; dl = sprintf(tbuf, ".%d", z->conflictctr); - strcpy(&name[l-dl], tbuf); + + if (l + dl < h->target_len) { + name = xrealloc(name, l + dl + 1); + strcat(name, tbuf); + } + else { + strcpy(&name[l-dl], tbuf); + } break; } } -- 2.30.2